﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
//using System.Linq;
using System.Text;
using System.Windows.Forms;
using LoggingDataAcceptor;
using BaseModel;

namespace LoggingDataMock
{
    public partial class Form1 : Form
    {
        private bool isMocking = false;
        private LoggingDataSender dataSender = new LoggingDataSenderImpl();
        private static int TestCurveCount = 5;
        private double testMD = 1000;
        private WellLoggingPoint gp = new WellLoggingPoint();

        public Form1()
        {
            InitializeComponent();
            gp.Value = new double[TestCurveCount];
            gp.Value[0] = 80;
            gp.Value[1] = 50;
            gp.Value[2] = 20;
            gp.Value[3] = 120;
            gp.Value[4] = 40;

        }

        private void button1_Click(object sender, EventArgs e)
        {
            isMocking = !isMocking;
            timer1.Enabled = isMocking;
            button1.Text = isMocking ? "结束采集" : "开始采集";
            if (isMocking)
            {
                Equipment eqm = new Equipment();
                eqm.Name = "SDZ-5000";
                eqm.Company = "22所";
                eqm.Model = "5000";
                eqm.PlaceOfProduction = "河南 新乡";
                WellInfo wi = new WellInfo();
                wi.Category = "采油井";
                wi.Name = "白208-10井";
                wi.StartMD = 2000;
                wi.WellType = "定向井";
                wi.EndMD = 3600;
                wi.Zone = "第一区";
                dataSender.InitLoggingInfo(eqm, wi);
                WellLoggingInfo[] wli = new WellLoggingInfo[TestCurveCount];
                wli[0] = new WellLoggingInfo();
                wli[0].Name = "GR";
                wli[1] = new WellLoggingInfo();
                wli[1].Name = "SP";
                wli[2] = new WellLoggingInfo();
                wli[2].Name = "DEN";
                wli[3] = new WellLoggingInfo();
                wli[3].Name = "声波时差";
                wli[4] = new WellLoggingInfo();
                wli[4].Name = "测速";
                dataSender.StartLoggingData(wli);
                listBox1.Items.Clear();
                listBox1.Items.Add("...开始采集数据....");
            }
            else
            {
                dataSender.EndLoggingData();
                testMD = 1000;
                listBox1.Items.Add(".....结束采集......");
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (isMocking)
            {
                Random r = new Random();
                gp.TestMD += 0.125;
                gp.TestTime = DateTime.Now;
               
                gp.Value[0] = gp.Value[0] + (20 - r.Next(40));
                gp.Value[1] = gp.Value[1] + (100 - r.Next(200));
                gp.Value[2] = gp.Value[2] + (30 - r.Next(60));
                gp.Value[3] = gp.Value[3] + (50 - r.Next(100));
                gp.Value[4] = gp.Value[4] + (70 - r.Next(140));
                listBox1.Items.Add("深度:" + gp.TestMD);
                listBox1.Items.Add("GR:" + gp.Value[0]);
                listBox1.Items.Add("SP:" + gp.Value[1]);
                listBox1.Items.Add("DEN:" + gp.Value[2]);
                listBox1.Items.Add("声波时差:" + gp.Value[3]);
                listBox1.Items.Add("测速:" + gp.Value[4]);
                dataSender.SendLoggingData(gp);
            }
        }
    }
}
